package com.qkm.xinguan.controller;

import com.qkm.xinguan.domain.entity.Comment;
import com.qkm.xinguan.exception.BindingResultException;
import com.qkm.xinguan.repository.impl.CommentService;
import com.qkm.xinguan.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zfj
 * @date 2021/12/29 -15:44
 */
@RestController
public class CommentController implements ICommentController{
	private final CommentService commentService;

	@Autowired
	public CommentController(CommentService commentService) {
		this.commentService = commentService;
	}

	@Override
	public Result addComment(Comment comment, BindingResult result) {
		if (result.hasErrors()) {
			throw new BindingResultException(result);
		}
		commentService.saveComment(comment);
		return Result.ok().message("添加评论成功");
	}

	@Override
	public Result getCommentListPage(String id, int page, int size) {
//		Page<Comment> commentPage= (Page<Comment>) ;
		return Result.ok().data(commentService.findByArticleid(id,page,size));
	}

	@Override
	public Result updateCommentLikeNum(String id) {
		commentService.updateCommentLikenum(id);
		return Result.ok().message("点赞成功");
	}

	@Override
	public Result updateCommentReplyNum(String id) {
		commentService.updateCommentReplyNum(id);
		return Result.ok().message("回复成功");
	}

}
